package com.example.administrator.readbook;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.example.administrator.readbook.greendao.DaoMaster;
import com.example.administrator.readbook.greendao.DaoSession;


/**
 * Created by Administrator on 2017/12/25 0025.
 */

public class MyApplication extends Application {
    //全局的上下文
    public static Context context;
    private static MyApplication instance;
    public static String token = "";
    private static DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
        instance = this;
        setDataBase();
    }

    private void setDataBase() {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(this, "Book.db", null);
        SQLiteDatabase db = devOpenHelper.getWritableDatabase();
        DaoMaster daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }

    /**
     * Application实例
     *
     * @return
     */
    public static MyApplication getInstance() {
        return instance;
    }

    public static DaoSession getDaoInstance() {
        return daoSession;
    }

    /**
     * 公共context
     *
     * @return
     */
    public static Context getContext() {
        return context;
    }
}
